package com.bawei.composeui2207a.day02

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.bawei.composeui2207a.R

/**
 * 作者：赵亮
 * 时间：2024/12/11 11:30
 * 功能：横向列表
 */

data class InfoEntity(val img: Int, val title: String, val content: String)

@Composable
fun Page8() {

    // 1. 数据 状态
    val list = mutableListOf<InfoEntity>()
    repeat(72) {
        list.add(
            InfoEntity(
                R.drawable.sunwukong,
                "孙悟空$it",
                "齐天大圣"
            )
        )
    }

    // 2. 横向列表
    LazyRow(modifier = Modifier.padding(top = 24.dp)) {
        items(list) {
            Row {
                Image(
                    modifier = Modifier
                        .size(100.dp)
                        .clip(CircleShape),
                    contentScale = ContentScale.Crop,
                    painter = painterResource(id = it.img),
                    contentDescription = null
                )
                Column(
                    modifier = Modifier.height(100.dp),
                    verticalArrangement = Arrangement.SpaceBetween  // 竖轴控件排布方式
                ) {
                    Text(text = it.title, modifier = Modifier.padding(top = 10.dp))
                    Text(text = it.content, modifier = Modifier.padding(top = 24.dp))
                }
            }
        }
    }
}

@Preview(showSystemUi = true)
@Composable
fun Page8Preview() {
    Page8()
}

